﻿--[[
   @brief    主面板社交tisp
   @author   rickonzhang
   @version  1.0
   @date     2015-12-13
--]]

social_tips_control = 
{
    social_user_level = 0;

    is_group_new_tab_clicked = false; --是否显示过群组new 
    is_friend_new_tab_clicked = false; --是否显示过好友new
    is_first_receive_message = false; --是否首次收到消息
    is_first_show_self_percenter = false;  --是否首次显示自己的个人中心

    is_head_img_show = false; --是否显示过头像引导

    init = function()
    end;

    do_check_need_show_head_img_tips = function()
        if social_tips_control.social_user_level ~= 0  and 
           social_tips_control.is_group_new_tab_clicked == false and
           social_tips_control.is_friend_new_tab_clicked == false and 
           social_tips_control.is_head_img_show == false then

            social_tips_control.is_head_img_show = true;
            social_tips_control.show_head_image_tips(TRUE);

       end
    end;

    --显示群组new 
    show_group_guide_tips = function(bShow)

        local main_uilib =  ui_utility.uilib();
        local mini_tab_id = main_uilib:GetControlIDbyCustomID(CID_MAIN_SOCIAL_FRIEND_CONTAINER_MINIUI);

        local max_mode_social_pannel_id = main_uilib:GetControlIDbyCustomID(CID_SOCIAL_PANEL_CTN);
        local ui_str, str_holder = U8toCUIStr("Cnt_Tabs");
        local max_tab_id = main_uilib:GetControlIDbyPath(ui_str, max_mode_social_pannel_id);

        local ui_str, str_holder = U8toCUIStr("Ctn_MainFrameTab\\ButtonGroup_Tab\\Btn_ContactPnl\\rect\\Container_New");

        if mini_tab_id > 0 then
            local mini_new_flag_id = main_uilib:GetControlIDbyPath(ui_str, mini_tab_id);
            local tips_ctrl = ui_utility.get_ctrl_ptr_by_id(mini_new_flag_id);
            if tips_ctrl then
                tips_ctrl:Show(bShow);
            end
        end

        if max_tab_id > 0 then
            local max_new_flag_id = main_uilib:GetControlIDbyPath(ui_str, max_tab_id);
            local tips_ctrl = ui_utility.get_ctrl_ptr_by_id(max_new_flag_id);
            if tips_ctrl then
                tips_ctrl:Show(bShow);
            end
        end

        if bShow == FALSE then
            social_tips_control.do_check_need_show_head_img_tips()
            social_tips_control.is_group_new_tab_clicked = true;
            social_tips_control.write_social_guide_cfg();
        end
    end;

    --显示好友new 
    show_friend_guide_tips = function(bShow)
        local main_uilib =  ui_utility.uilib();
        local mini_tab_id = main_uilib:GetControlIDbyCustomID(CID_MAIN_SOCIAL_FRIEND_CONTAINER_MINIUI);

        local max_mode_social_pannel_id = main_uilib:GetControlIDbyCustomID(CID_SOCIAL_PANEL_CTN);
        local ui_str, str_holder = U8toCUIStr("Cnt_Tabs");
        local max_tab_id = main_uilib:GetControlIDbyPath(ui_str, max_mode_social_pannel_id);

        local ui_str, str_holder = U8toCUIStr("Ctn_MainFrameTab\\ButtonGroup_Tab\\Btn_SessionPnl\\rect\\Container_New");

        if mini_tab_id > 0 then
            local mini_new_flag_id = main_uilib:GetControlIDbyPath(ui_str, mini_tab_id);
            local tips_ctrl = ui_utility.get_ctrl_ptr_by_id(mini_new_flag_id);
            if tips_ctrl then
                tips_ctrl:Show(bShow);
            end
        end

        if max_tab_id > 0 then
            local max_new_flag_id = main_uilib:GetControlIDbyPath(ui_str, max_tab_id);
            local tips_ctrl = ui_utility.get_ctrl_ptr_by_id(max_new_flag_id);
            if tips_ctrl then
                tips_ctrl:Show(bShow);
            end
        end


        if bShow == FALSE then
            social_tips_control.do_check_need_show_head_img_tips()
            social_tips_control.is_friend_new_tab_clicked = true;
            social_tips_control.write_social_guide_cfg();
        end
    end;

    --点击个人中心时关闭头像tips
    show_personal_center = function(event_id, json_str)
        local param_table = base_utility.json_to_table(json_str);
        if param_table["friend_id"] == login_model.im_login_infomation.friend_id then
            social_tips_control.show_head_image_tips(FALSE);
        end
    end;

    --判断头像tips是否打开
    is_head_img_tips_show = function()
        local tips_ctrl = ui_utility.get_ctrl_ptr_by_cid(CID_MAIN_SOCIAL_HEAD_IMG_NEW_TIP);
        if tips_ctrl and tips_ctrl:IsVisible() == TRUE then
            return true;
        else
            return false;
        end
    end;

    --显示头像tips
    show_head_image_tips = function(bShow)
        local tips_ctrl = ui_utility.get_ctrl_ptr_by_cid(CID_MAIN_SOCIAL_HEAD_IMG_NEW_TIP);
        if tips_ctrl then
            tips_ctrl:Show(bShow);
        end

        if bShow == TRUE then
            social_tips_control.start_timer_for_head_img_tips();
        else
            social_tips_control.stop_timer_for_head_img_tips();
        end
    end;

    start_timer_for_head_img_tips = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddInterval('social_tips_control.on_timer_for_head_img_tips', 10000);
    end;

    stop_timer_for_head_img_tips = function()
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:RemoveInterval('social_tips_control.on_timer_for_head_img_tips');
    end;

    --如果没点击个人头像，则3s后自动隐藏
    on_timer_for_head_img_tips = function()
        social_tips_control.stop_timer_for_head_img_tips();
        social_tips_control.show_head_image_tips(FALSE);
    end;

    --第一次收到通知
    on_show_notify_number = function(event_id, json_str)
        if social_tips_control.social_user_level ~= 0 and 
           social_tips_control.is_first_receive_message == false then

            local param_table = base_utility.json_to_table(json_str);
            if param_table["number"] > 0 then
                base_utility.log("[social_tips_control] on_show_notify_number: first receve", true);
                social_tips_control.is_first_receive_message = true;
                social_tips_control.show_message_box_btn_guide_tips(TRUE);
                social_tips_control.write_social_guide_cfg();
            end
        end
    end;

    --打开消息盒子是关闭消息盒子tips
    show_message_box = function(event_id, json_str)
        --social_tips_control.show_message_box_btn_guide_tips(FALSE);
    end;

    show_message_box_btn_guide_tips = function(bShow)
        ierd_tgp.tpf_ui.Require("social\\social_tips\\social_msg_box_notify.lua");
        social_msg_box_notify_tips.show();
    end;

    --主面板tab：游戏、好友、群创建
    on_group_tips_created = function(uilib, ctrl_id)
        if social_tips_control.social_user_level ~= 0  and
           social_tips_control.is_group_new_tab_clicked == false then
            -- 屏蔽群组tab new
            -- social_tips_control.show_group_guide_tips(TRUE);
        end
    end;

    on_friend_tips_created = function(uilib, ctrl_id)
        if social_tips_control.social_user_level ~= 0  and
            social_tips_control.is_friend_new_tab_clicked == false then
            -- 屏蔽，不显示好友tab new
            -- social_tips_control.show_friend_guide_tips(TRUE);
        end
    end;

    is_first_show_my_center = function()
        local ret = false;
        if social_tips_control.social_user_level ~= 0 and 
           social_tips_control.is_first_show_self_percenter == false then

            social_tips_control.is_first_show_self_percenter = true;
            social_tips_control.write_social_guide_cfg();
            ret = true;
        end
        return ret;
    end;

    on_get_my_social_test_info = function(event_id, json_str)
        local param = base_utility.json_to_table(json_str);

        social_tips_control.social_user_level = param["level"];
        if social_tips_control.social_user_level ~= 0 then
            social_tips_control.read_social_guide_cfg();             
            social_tips_control.on_group_tips_created(nil, nil);
            social_tips_control.on_friend_tips_created(nil, nil);
        end
    end;

    read_social_guide_cfg = function()
        local param = comm_center.call_service("im_app_service_get_social_guide_cfg", {});
        if param == nil then return end
        local parm_tbl = base_utility.json_to_table(param.social_guide_cfg);

        if parm_tbl.is_group_new_tab_clicked ~= nil then
            social_tips_control.is_group_new_tab_clicked = parm_tbl.is_group_new_tab_clicked; 
        end

        if parm_tbl.is_friend_new_tab_clicked ~= nil then
            social_tips_control.is_friend_new_tab_clicked = parm_tbl.is_friend_new_tab_clicked; 
        end

        if parm_tbl.is_first_receive_message ~= nil then
            social_tips_control.is_first_receive_message = parm_tbl.is_first_receive_message; 
        end

        if parm_tbl.is_first_show_self_percenter ~= nil then
            social_tips_control.is_first_show_self_percenter = parm_tbl.is_first_show_self_percenter; 
        end
    end;

    write_social_guide_cfg = function()
        local parm_tbl = {};        
        parm_tbl.is_group_new_tab_clicked = social_tips_control.is_group_new_tab_clicked; 
        parm_tbl.is_friend_new_tab_clicked = social_tips_control.is_friend_new_tab_clicked; 
        parm_tbl.is_first_receive_message = social_tips_control.is_first_receive_message ; 
        parm_tbl.is_first_show_self_percenter = social_tips_control.is_first_show_self_percenter; 
        local out = comm_center.call_service("im_app_service_set_social_guide_cfg", {social_guide_cfg =base_utility.table_to_json(parm_tbl)});
    end;
}

social_tips_control.init();